//
//  GL_TC_Tank.m
//  RecipeCollection02
//
//  Created by Louis CHU on 27/02/12.
//  Copyright (c) 2012 Nathan Burba. All rights reserved.
//

#import "GL_TC_Tank.h"
#import "GL_TestCollision.h"
@implementation GL_TC_Tank
+ (GL_TC_Tank *) createAtPosition: (CGPoint) pos;
{    
    GL_TC_Tank * newTank = [[GL_TC_Tank alloc] init];
    newTank.gameArea = [GL_TestCollision sharedInstance];
    newTank.bodyDef->type = b2_dynamicBody;
    newTank.bodyDef->position.Set(pos.x/PTM_RATIO, pos.y/PTM_RATIO);
    newTank.bodyDef->userData = newTank;
    newTank.bodyDef->linearDamping = 1.f;
    newTank.bodyDef->angularDamping = 1.f;
    newTank.body = [[GL_TestCollision sharedInstance] world]->CreateBody(newTank.bodyDef);
    
    newTank.fixtureDef->density = 1.0f;
	newTank.fixtureDef->friction = 1.f;
	newTank.fixtureDef->restitution = 0.0f;
	
    float textureSize = 128;
    float shapeSize = 16;
		
    newTank.sprite = [CCSprite spriteWithFile:@"box2.png"];
    newTank.sprite.position = ccp(pos.x,pos.y);
    newTank.sprite.scale = shapeSize / textureSize * 2;
        
    [[[GL_TestCollision sharedInstance] gameNode] addChild:newTank.sprite];
		
    newTank.polygonShape = new b2PolygonShape();
    newTank.polygonShape->SetAsBox(shapeSize/PTM_RATIO, shapeSize/PTM_RATIO);	
    newTank.fixtureDef->shape = newTank.polygonShape;
		
    newTank.body->CreateFixture(newTank.fixtureDef);
    
    [newTank.sprite setColor:ccc3(0, 255, 0)];
    
    newTank.maxSpeed = 0.5f;
    newTank.bRadius = 25;
    
    
    
    return newTank;
}
@end
